package cn.qyd.socket;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
 * @author 邱运铎
 * @date 2024-03-12 1:23
 */
public class SocketDemo {
    public static void main(String[] args) {
        try(Socket socket = new Socket("bbs.newsmth.net",23);) {
            socket.setSoTimeout(10000);
            InputStream is = socket.getInputStream();
            Scanner scanner = new Scanner(is,"gbk");
            while (scanner.hasNext()) {
                String line = scanner.nextLine();
                System.out.println(line);
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
